package com.linsen.core.rule.constant;

/**
 * 规则常量
 *
 * @author zhaoyong
 * @date 2023/3/13
 */
public interface RuleConstant {
    String LOCALHOST = "localhost";
    String LOCALHOST_IP = "127.0.0.1";

    String ALL = "all";
    String DENY_OPEN = "0";
    String DENY_CLOSE = "1";

    String DENY_CACHE_KEY_PREFIX = "linsen:rule:deny:";

    static String getDenyCacheKey(String ip) {
        if (LOCALHOST.equalsIgnoreCase(ip)) {
            ip = LOCALHOST_IP;
        }
        return String.format("%s%s", DENY_CACHE_KEY_PREFIX, ip);
    }

    static String getDenyCacheKey() {
        return String.format("%s" + ALL, DENY_CACHE_KEY_PREFIX);
    }
}
